package com.hawk.eye.client.toolkit;


import org.slf4j.MDC;

import java.util.Map;

/**
 * @className: LogPropertyHolder
 * @description: MDC的工具类
 * @author: salad
 * @date: 2023/9/21
 **/
public class LogPropertyHolder {

    public static void put(String key, String val) {
        MDC.put(key, val);
    }

    public static void puts(String keys, String... values) {
        String[] keysArray = keys.split(",");
        for (int i = 0; i < keysArray.length; i++) {
            if (keysArray[i] != null && keysArray[i].trim().length() > 0) {
                MDC.put(keysArray[i].trim(), values[i]);
            }
        }
    }

    public static String get(String key, String defaultValue) {
        String value = MDC.get(key);
        return  value == null ? defaultValue : value;
    }

    public static Map<String, String> getCopyOfContextMap() {
        return MDC.getCopyOfContextMap();
    }

    public static void removes(String keys) {
        String[] keysArray = keys.split(",");
        for (String s : keysArray) {
            if (s != null && s.trim().length() > 0) {
                MDC.remove(s.trim());
            }
        }
    }
}
